package cn.com.roy.thread.t3_1_3.test3;

public class ThreadB extends Thread {
    private Object lock;

    public ThreadB(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        super.run();
        try {
            synchronized (lock) {
                for (int i = 0; i < 10; i++) {
                    TransService.add();
                    if(TransService.size() == 5){
                        lock.notify();
                        System.out.println("通知已发出！");
                    }
                    System.out.println("添加了 "+(i+1)+" 个元素");
                    Thread.sleep(1000);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
